package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.CustomerBean;
import com.project.bean.ProductBean;
import com.project.bean.SellCarBean;
import com.project.bean.UserBean;
import com.project.service.ISellCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RequestMapping("sellCar")
@RestController
public class SellCarController {
    @Autowired
    private ISellCarService sellCarService;

    @RequestMapping("findAll")
    public List<CustomerBean> findAll(){
        return sellCarService.findAll();
    }

    @RequestMapping("findBySellerId")
    public  List<SellCarBean> findBySellerId(Integer sellerId, HttpServletRequest request){
        UserBean userBean = (UserBean) request.getSession().getAttribute("loginUser");
        return sellCarService.findBySellerId(userBean.getUserId());
    }

    @RequestMapping("findByItem")
    public IPage<ProductBean> findByItem(Integer pageNO, String productType, String productName){
        return sellCarService.findByItem(pageNO, productType, productName);
    }

    @RequestMapping("addProductInSellCar")
    public String addProductInSellCar(Integer productId){
        sellCarService.addProductInSellCar(productId);
        return "success";
    }

    @RequestMapping("delProductInSellCar")
    public String delProductInSellCar(Integer sellCarId){
        sellCarService.delProductInSellCar(sellCarId);
        return "success";
    }

    @RequestMapping("updateProductNumInSellCar")
    public String updateProductNumInSellCar(Integer sellCarId,Integer newNum){
        sellCarService.updateProductNumInSellCar(sellCarId,newNum);
        return "success";
    }
}
